{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 支持向量机（SVM）\n",
    "from sklearn.svm import LinearSVC # 线性SVM\n",
    "\n",
    "from sklearn.datasets import make_blobs # 生成数据集\n",
    "\n",
    "from sklearn.model_selection import train_test_split # 划分数据集\n",
    "from sklearn.metrics import accuracy_score # 计算准确率"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "centers = [(-1,-0.125),(0.5,0.5)] # 生成数据集中心\n",
    "X, y = make_blobs(n_samples=50, centers=centers, cluster_std=0.3,n_features=2) # 生成数据集\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3) # 划分数据集\n",
    "\n",
    "model = LinearSVC() # 创建线性SVM模型\n",
    "model.fit(X_train, y_train) # 训练模型\n",
    "y_pred = model.predict(X_test) # 预测测试集\n",
    "accuracy = accuracy_score(y_test, y_pred) # 计算准确率\n",
    "accuracy"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "ml",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
